package xin.printk.android.module.plan;

import xin.printk.android.data.entity.Plan;
import xin.printk.android.utils.RequestCallback;

public class EditPlanPresenter implements EditPlanContract.Presenter {

    private EditPlanContract.View mView;

    public EditPlanPresenter(EditPlanContract.View view) {
        mView = view;
    }

    @Override
    public void getPlan() {
        PlanModel.getPlan(mView.getContext(), mView.getPlanId(), new RequestCallback() {
            @Override
            public <T> void onSuccess(T t) {
                Plan plan = (Plan) t;
                mView.initData(plan);
            }

            @Override
            public void onFailure(String message) {

            }
        });
    }

    @Override
    public void updatePlan() {
        PlanModel.updatePlan(mView.getContext(), mView.getPlan(), new RequestCallback() {

            @Override
            public <T> void onSuccess(T t) {
                mView.edit();
            }

            @Override
            public void onFailure(String message) {
                mView.showError(message);
            }
        });
    }
}
